import 'package:flutter/material.dart';
import 'package:flutter_blog_manage_study/base/get/get_common_view.dart';
import 'package:flutter_blog_manage_study/res/r.dart';
import 'package:flutter_blog_manage_study/res/strings.dart';
import 'package:flutter_blog_manage_study/routes/routes.dart';
import 'package:flutter_blog_manage_study/ui/page/splash/splash_controller.dart';
import 'package:flutter_blog_manage_study/util/sp/sp_util.dart';
import 'package:get/get.dart';

/// * 作者: Tao
/// * 日期: 2024/3/22
/// * 时间: 14:08
/// * 描述: splash 动画widget
class SplashAnimWidget extends GetCommonView<SplashController> {
  const SplashAnimWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return AnimatedOpacity(
      // 实现淡入淡出的动画效果
      opacity: controller.opacityLevel, // 设置透明度
      duration: const Duration(seconds: 1),
      onEnd: () {
        // 动画结束后判断是否在本地保存有用户信息，来跳转到登录页或者首页
        Get.offNamed(
            SPUtil.getUserInfo() == null ? Routes.loginPage : Routes.homePage);
      },
      child: Container(
        // 离上方120dp 居中，纵向排列图片、文字
        margin: const EdgeInsets.only(top: 120),
        alignment: Alignment.center,
        child: Column(
          children: [
            Image.asset(
              R.assetsImagesApplication,
              fit: BoxFit.fitWidth,
              width: 120,
              height: 120,
            ),
            Container(
              margin: const EdgeInsets.only(top: 16),
              child: Text(
                Strings.appName.tr,
                style: const TextStyle(fontSize: 36, color: Colors.black),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
